// FM_V_BPA.cpp: implementation of the CFM_V_BPA class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "../../Include/Swi/FM_V_BPA.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CFM_V_BPA::CFM_V_BPA()
{
	m_chType = 'F';
	m_chSubType = 'M';
	m_chChangeCode = ' ';

	m_dRc = 0;
	m_dXc = 0;
	m_dTr = 0;
	m_dK = 0;
	m_dKv = 0;
	m_dT1 = 0;
	m_dT2 = 0;
	m_dT3 = 0;
	m_dT4 = 0;
	m_dKa = 0;
	m_dTa = 0;
	m_dKf = 0;
	m_dTf = 0;
	m_dKh = 0;

	m_strCardType[0] = 'F';
	m_strCardType[1] = '1';
}


CFM_V_BPA::CFM_V_BPA(CFM_V_BPA &fmvBPA):CUnit_BPA(fmvBPA)
{
	m_dRc = fmvBPA.m_dRc;
	m_dXc = fmvBPA.m_dXc;
	m_dTr = fmvBPA.m_dTr;
	m_dK = fmvBPA.m_dK;
	m_dKv = fmvBPA.m_dKv;
	m_dT1 = fmvBPA.m_dT1;
	m_dT2 = fmvBPA.m_dT2;
	m_dT3 = fmvBPA.m_dT3;
	m_dT4 = fmvBPA.m_dT4;
	m_dKa = fmvBPA.m_dKa;
	m_dTa = fmvBPA.m_dTa;
	m_dKf = fmvBPA.m_dKf;
	m_dTf = fmvBPA.m_dTf;
	m_dKh = fmvBPA.m_dKh;
}

CFM_V_BPA::~CFM_V_BPA()
{

}

bool CFM_V_BPA::FillEx(char *buffer)
{
	bool bResult = CUnit_BPA::FillEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFM_V_BPA: FillEx): no basic information!\n");
		return false;
	}

	if (strlen(buffer)<17)
	{
		printf("Error in (CFM_V_BPA: FillEx): FM_V has no parameter!\n");
		return false;
	}

	m_dRc = StrToDouble(&buffer[16],4,3);
	if(EndOfSec(&buffer[16],4))
		return true;

	m_dXc = StrToDouble(&buffer[20],4,3);
	if(EndOfSec(&buffer[20],4))
		return true;

	m_dTr = StrToDouble(&buffer[24],5,3);
	if(EndOfSec(&buffer[24],5))
		return true;

	m_dK = StrToDouble(&buffer[29],5,3);
	if(EndOfSec(&buffer[29],5))
		return true;

	m_dKv = StrToDouble(&buffer[34],3,0);
	if(EndOfSec(&buffer[34],3))
		return true;

	m_dT1 = StrToDouble(&buffer[37],5,3);
	if(EndOfSec(&buffer[37],5))
		return true;

	m_dT2 = StrToDouble(&buffer[42],5,3);
	if(EndOfSec(&buffer[42],5))
		return true;

	m_dT3 = StrToDouble(&buffer[47],5,3);
	if(EndOfSec(&buffer[47],5))
		return true;

	m_dT4 = StrToDouble(&buffer[52],5,3);
	if(EndOfSec(&buffer[52],5))
		return true;

	m_dKa = StrToDouble(&buffer[57],5,3);
	if(EndOfSec(&buffer[57],5))
		return true;

	m_dTa = StrToDouble(&buffer[62],5,3);
	if(EndOfSec(&buffer[62],5))
		return true;

	m_dKf = StrToDouble(&buffer[67],5,3);
	if(EndOfSec(&buffer[67],5))
		return true;

	m_dTf = StrToDouble(&buffer[72],4,3);
	if(EndOfSec(&buffer[72],4))
		return true;

	m_dKh = StrToDouble(&buffer[76],4,2);
	if(EndOfSec(&buffer[76],4))
		return true;
	return true;
}

bool CFM_V_BPA::UpdateEx(char *buffer)
{
	bool bResult = CUnit_BPA::UpdateEx(buffer);

	if (!bResult)
	{
		printf("Error in (CFM_V_BPA: UpdateEx): impossible!\n");
		return false;
	}

	DoubleToStr(m_dRc,&buffer[16],4,3);
	DoubleToStr(m_dXc,&buffer[20],4,3);
	DoubleToStr(m_dTr,&buffer[24],5,3);
	DoubleToStr(m_dK,&buffer[29],5,3);
	DoubleToStr(m_dKv,&buffer[34],3,0);
	DoubleToStr(m_dT1,&buffer[37],5,3);
	DoubleToStr(m_dT2,&buffer[42],5,3);
	DoubleToStr(m_dT3,&buffer[47],5,3);
	DoubleToStr(m_dT4,&buffer[52],5,3);
	DoubleToStr(m_dKa,&buffer[57],5,3);
	DoubleToStr(m_dTa,&buffer[62],5,3);
	DoubleToStr(m_dKf,&buffer[67],5,3);
	DoubleToStr(m_dTf,&buffer[72],4,3);
	DoubleToStr(m_dKh,&buffer[76],4,2);

	return true;
}